﻿using System;

namespace diantou.web.enterprise
{
    /// <summary>
    /// 企业用户权限视图
    /// </summary>
    /// <typeparam name="viewType"></typeparam>
    abstract class view<viewType> : web.view<viewType>
        where viewType : view<viewType>
    {
        /// <summary>
        /// 当前用户
        /// </summary>
        private diantou.examDataAccess.enterprise enterprise;
        /// <summary>
        /// 当前用户
        /// </summary>
        protected diantou.examDataAccess.enterprise currentEnterprise
        {
            get
            {
                if (enterprise == null)
                {
                    if (currentUser != null) enterprise = examDataAccess.clientCache.Enterprise[currentUserId];
                    if (enterprise == null) enterprise = diantou.examDataAccess.enterprise.NullEnterprise;
                }
                return enterprise != diantou.examDataAccess.enterprise.NullEnterprise ? enterprise : null;
            }
        }
        /// <summary>
        /// 是否存在企业独占题库权限
        /// </summary>
        protected bool isEnterprisePrivateValidity
        {
            get { return currentEnterprise.IsEnterprisePrivateValidity || currentUser.Permission == dataModel.user.permission.Admin; }
        }
        /// <summary>
        /// 是否考试人员列表页面
        /// </summary>
        protected virtual bool isUserPage
        {
            get { return false; }
        }
        /// <summary>
        /// 是否判卷人员可访问页面
        /// </summary>
        protected virtual bool isReviewerPage
        {
            get { return false; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override bool loadView()
        {
            if (base.loadView())
            {
                if (currentUser != null)
                {
                    if (isReviewerPage || currentUser.IsEnterprisePermission) return true;
                }
                AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = diantou.dataModel.path.pub.EnterpriseLogin });
            }
            return false;
        }
        /// <summary>
        /// 清除页面信息
        /// </summary>
        protected override void clear()
        {
            base.clear();
            enterprise = null;
        }
    }
}
